from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Edge()
driver.get('https://www.itcast.cn/')

# 隐式等待
driver.implicitly_wait(10)          # 设置等待时间为10s
driver.switch_to.frame('chatIframe')        # 聊天窗口由<iframe>标签创建的
element = driver.find_element(By.CLASS_NAME, 'service')
print(element.text)

# 显式等待
element = WebDriverWait(driver, 10).until(lambda x: x.find_element(By.CLASS_NAME, 'service'))
print(element.text)

# 内置等待条件
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'service')))
print(element.text)
